package com.atguigu.springboot.controller;

import com.atguigu.springboot.entity.User;
import com.atguigu.springboot.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author admin
 * @create 2020-03-29 16:41
 */
@RestController
public class UserController {

    @Autowired
    private UserRepository userRepository;

    /**
     * 查询单个用户信息
     * @param id
     * @return
     */
    @GetMapping("/user/{id}")
    public User getId(@PathVariable(name = "id") Integer id){
        User user = userRepository.findOne(id);
        return user;
    }

    /**
     * 插入一个用户信息
     * @param user
     * @return
     */
    @GetMapping("/user")
    public User insert(User user){
        User save = userRepository.save(user);
        return save;
    }
}
